import React, { Component } from 'react';
import {Button,Icon,Modal,Form} from 'antd';
import axios from 'axios';
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

export default class Edit extends Component{
    constructor(props){
        super(props);
        this.state={
            show:false,
            layerstyle:props.layerstyle,
            editdata:{
            },
            key:''
        }
        this.confirm=this.confirm.bind(this);
    }
    confirm(){
        let tmp = this.myform.form.getFieldsValue();
        // axios({
        //     method:'post',
        //     url:'http://cloud.jss.com.cn/order/invoice/saveInvoice.do',
        //     data:tmp,
        // }).then((res)=>{
        //     if(res.data.result && res.data.result =='success'){
        //         tmp.id=res.data.data.id;
        //         this.props.databack(tmp,tmp.key);
        //         this.setState({
        //             show:false
        //         })
        //     }
        // })
        $.ajax({
            type:'post',
            url:'http://cloud.jss.com.cn/order/invoice/saveInvoice.do',
            data:tmp,
            dataType:'json',
            success:(res)=>{
                if(res.result && res.result =='success'){
                    tmp.id=res.data.id;
                    this.props.databack(tmp,tmp.key);
                }
            }
        })
    }
    render(){
        const Formlayer = Form.create({})(this.props.component)
        if(this.state.show === true){
            return(
                <Modal visible={this.state.show}
                destroyOnClose={true}   
                onCancel={()=>{this.setState({show:false})}}
                onOk={this.confirm}
                style={this.state.layerstyle}
                wrapClassName="editlayer"
                mask={false}
                width={456}
                closable={false}
                okText="确定"
                cancelText="取消"
                databack= {this.props.databack}
                >
                <Formlayer wrappedComponentRef={(form) => this.myform = form} editdata={this.state.editdata} keyid={this.state.key} type={this.props.type}/>
                </Modal>
            )
        }else{
            return (<React.Fragment></React.Fragment>)
        }
    }
}